package com.ruoyi.exam.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamRespond;
import com.ruoyi.exam.service.IExamRespondService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 考生作答Controller
 * 
 * @author ba7lgj
 * @date 2024-04-03
 */
@RestController
@RequestMapping("/exam/respond")
public class ExamRespondController extends BaseController
{
    @Autowired
    private IExamRespondService examRespondService;

    /**
     * 查询考生作答列表
     */
    @PreAuthorize("@ss.hasPermi('exam:respond:list')")
    @GetMapping("/list")
    public TableDataInfo list(ExamRespond examRespond)
    {
        startPage();
        List<ExamRespond> list = examRespondService.selectExamRespondList(examRespond);
        return getDataTable(list);
    }

    /**
     * 导出考生作答列表
     */
    @PreAuthorize("@ss.hasPermi('exam:respond:export')")
    @Log(title = "考生作答", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamRespond examRespond)
    {
        List<ExamRespond> list = examRespondService.selectExamRespondList(examRespond);
        ExcelUtil<ExamRespond> util = new ExcelUtil<ExamRespond>(ExamRespond.class);
        util.exportExcel(response, list, "考生作答数据");
    }

    /**
     * 获取考生作答详细信息
     */
    @PreAuthorize("@ss.hasPermi('exam:respond:query')")
    @GetMapping(value = "/{recordId}")
    public AjaxResult getInfo(@PathVariable("recordId") Long recordId)
    {
        return success(examRespondService.selectExamRespondByRecordId(recordId));
    }

    /**
     * 新增考生作答
     */
    @PreAuthorize("@ss.hasPermi('exam:respond:add')")
    @Log(title = "考生作答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamRespond examRespond)
    {
        return toAjax(examRespondService.insertExamRespond(examRespond));
    }

    /**
     * 修改考生作答
     */
    @PreAuthorize("@ss.hasPermi('exam:respond:edit')")
    @Log(title = "考生作答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamRespond examRespond)
    {
        return toAjax(examRespondService.updateExamRespond(examRespond));
    }

    /**
     * 删除考生作答
     */
    @PreAuthorize("@ss.hasPermi('exam:respond:remove')")
    @Log(title = "考生作答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{recordIds}")
    public AjaxResult remove(@PathVariable Long[] recordIds)
    {
        return toAjax(examRespondService.deleteExamRespondByRecordIds(recordIds));
    }
}
